package com.alavente.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.alavente.objects.Categorie;

public class ObtenirSousCategorieAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
	{
		int numCat = 0;
		
		try {
			numCat = Integer.parseInt(request.getParameter("numCategorie"));
		}
		catch (NumberFormatException e)
		{
			
		}
		
		List<Categorie> categories = (List<Categorie>) servlet.getServletContext().getAttribute("categories");
		
		for (Categorie cat : categories) {
			if (cat.getNumCat() == numCat)
				request.setAttribute("ssCategories", cat.getSsCategories());
		}
		
		return mapping.findForward("success");
	}

}
